package org.come.Frame;

import com.tool.tcpimg.UIUtils;
import come.tool.Fighting.FightingMixDeal;
import org.come.Jpanel.HuaLianJpanel;
import org.come.until.FormsManagement;
import org.come.until.Music;

import javax.swing.*;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class HuaLianJframe extends JInternalFrame implements MouseListener {
    private HuaLianJpanel huaLianJpanel;
    private int first_x;
    private int first_y;

    public static HuaLianJframe getHuaLianJframe() {
        return (HuaLianJframe) FormsManagement.getInternalForm(701).getFrame();
    }

    public HuaLianJframe() throws Exception {
        this.add(this.huaLianJpanel = new HuaLianJpanel());

        this.setBorder(BorderFactory.createEmptyBorder());
        ((BasicInternalFrameUI)this.getUI()).setNorthPane(null);
        this.setBounds(400, 100, 414, 416);
        this.setBackground(UIUtils.Color_BACK);
        this.pack();
        this.setDefaultCloseOperation(3);
        this.setVisible(false);
        this.addMouseListener(this);
        this.addMouseMotionListener(new MouseMotionListener() {
            @Override
            public void mouseMoved(final MouseEvent e) {
            }

            @Override
            public void mouseDragged(final MouseEvent e) {
                if (HuaLianJframe.this.isVisible()) {
                    final int x = e.getX() - HuaLianJframe.this.first_x;
                    final int y = e.getY() - HuaLianJframe.this.first_y;
                    HuaLianJframe.this.setBounds(x + HuaLianJframe.this.getX(), y + HuaLianJframe.this.getY(), HuaLianJframe.this.getWidth(), HuaLianJframe.this.getHeight());
                }
            }
        });
    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {
        Music.addyinxiao("关闭窗口.mp3");
        if (e.isMetaDown()) {
            FightingMixDeal.zdhh = 0;
            FormsManagement.HideForm(701);
        } else {
            FormsManagement.Switchinglevel(701);
        }

        this.first_x = e.getX();
        this.first_y = e.getY();
    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

    public HuaLianJpanel getHuaLianJpanel() {
        return huaLianJpanel;
    }

    public void setHuaLianJpanel(HuaLianJpanel huaLianJpanel) {
        this.huaLianJpanel = huaLianJpanel;
    }
}
